package vip.xiaonuo.pm.modular.enterprise.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.param.DeleteByIdParam;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.pm.modular.enterprise.entity.PmEnterpriseEntity;
import vip.xiaonuo.pm.modular.enterprise.param.EnterpriseAddParam;
import vip.xiaonuo.pm.modular.enterprise.param.EnterpriseEditParam;
import vip.xiaonuo.pm.modular.enterprise.param.EnterprisePageParam;
import vip.xiaonuo.pm.modular.enterprise.service.PmEnterpriseService;

import java.util.List;

/**
 * <p>
 * 客户 前端控制器
 * </p>
 *
 * @author xhs
 * @since 2025-06-04
 */
@Tag(name = "客户控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 3)
@Validated
@RestController
@RequestMapping("/pm/enterprise/")
public class PmEnterpriseController {

    @Resource
    private PmEnterpriseService pmEnterpriseService;

    /**
     * 新增客户
     *
     * @param enterpriseAddParam 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "新增客户")
    @CommonLog("新增客户")
    @SaCheckPermission("/pm/enterprise/add")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Validated EnterpriseAddParam enterpriseAddParam) {
        pmEnterpriseService.add(enterpriseAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑客户
     *
     * @param enterpriseEditParam 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 2)
    @Operation(summary = "编辑客户")
    @CommonLog("编辑客户")
    @SaCheckPermission("/pm/enterprise/edit")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Validated EnterpriseEditParam enterpriseEditParam) {
        pmEnterpriseService.edit(enterpriseEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除客户
     *
     * @param DeleteIdParamList 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "删除客户")
    @CommonLog("删除客户")
    @SaCheckPermission("/pm/enterprise/delete")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空") List<DeleteByIdParam> DeleteIdParamList) {
        pmEnterpriseService.delete(DeleteIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取客户分页
     *
     * @param enterprisePageParam 入参
     * @return CommonResult<Page < PmEnterpriseEntity>>
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "获取客户分页")
    @SaCheckPermission("/pm/enterprise/page")
    @PostMapping("/page")
    public CommonResult<Page<PmEnterpriseEntity>> page(@RequestBody @Validated EnterprisePageParam enterprisePageParam) {
        return CommonResult.data(pmEnterpriseService.page(enterprisePageParam));
    }
}
